unit UntSalermenDB;

interface

uses
  Classes;

type
  TSalermenDB = class(TObject)
  public
    class function insertSaleMen(aUserNameList: TStringList; hdid: Integer;
        asaleMoney:Double): Boolean;
  end;

implementation

uses
  Math, defineConst, UntDMDB;

class function TSalermenDB.insertSaleMen(aUserNameList: TStringList; hdid:
    Integer; aSaleMoney:Double): Boolean;
var sqlStr : string;
  lsaleMoney :Double;
  index : Integer;
begin
  Result := False;
  if (aUserNameList.Count=0) then
    Exit;

  lsaleMoney  :=  aSaleMoney / (aUserNameList.Count);
  lsaleMoney := RoundTo(lsaleMoney,cDecimalDigits);
  sqlStr := ' insert into salermenInf(hdid,saler,saleMoney) '
         + ' value(:hdid,:saler,:saleMoney)';
  for index := 0 to aUserNameList.Count - 1 do
  begin
    DMMySQL.mycmdCom.SQL.Clear;
    DMMySQL.mycmdCom.SQL.Add(sqlStr);
    DMMySQL.mycmdCom.ParamByName('hdid').AsInteger :=hdid;
    DMMySQL.mycmdCom.ParamByName('saler').AsString :=aUserNameList.Strings[index];
    DMMySQL.mycmdCom.ParamByName('saleMoney').AsFloat := lsaleMoney;
    DMMySQL.mycmdCom.Execute;
  end;
  Result := True;

end;

end.
